package com.wyiot.pet.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyiot.pet.mapper.WayBillMapper;
import com.wyiot.pet.model.entity.OrderDO;
import com.wyiot.pet.model.entity.WayBillDO;
import com.wyiot.pet.model.entity.WayBillMessageDO;
import com.wyiot.pet.model.vo.WaybillDetailVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户运单Service
 *
 * @author yly
 * @since 2022年04月06日
 */
@Service
public class WayBillService extends ServiceImpl<WayBillMapper, WayBillDO> {
    @Resource
    WaybillMessageService waybillMessageService;
    /**
     * 查看运单详情
     *
     * @param waybillId 运单id
     */
    public WaybillDetailVO queryWaybillById(Long waybillId) {
        /*根据运单查询运单最新详情*/
        WaybillDetailVO waybillDetailVO = baseMapper.selectWaybillDetailByWaybillId(waybillId);
        /*查詢运单对应消息*/
        List<WayBillMessageDO> list = waybillMessageService.list(new LambdaQueryWrapper<>(WayBillMessageDO.class).eq(WayBillMessageDO::getWayBillId, waybillId));
        waybillDetailVO.setWaybillMessage(list);
        return waybillDetailVO;
    }

    /**
     * 根据运单id查询订单
     *
     * @param waybillId 运单id
     */
    public OrderDO queryOrderByWaybillId(Long waybillId) {
        return baseMapper.selectOrderByWayBillId(waybillId);
    }

}
